
ALTER  proc sp_update_quarter_nos_for_legacy_CompanyCalendar_data
as
begin
	declare @temp_yearId int
	declare	@quarter_no int
	declare @temp_quarter_id int	
	declare temp_cursor1 cursor for select cc_yearId from company_calendar
	open temp_cursor1
	fetch next from temp_cursor1 into @temp_yearId
	while @@fetch_status = 0
		Begin			
			declare temp_cursor2 cursor for	select cqc_quarter_Id from company_quarterly_calendar where cqc_yearId = @temp_yearId order by cqc_quarter_Id
			open temp_cursor2 
			set @quarter_no = 1
			fetch next from temp_cursor2 into @temp_quarter_id
			
			while @@fetch_status = 0
				begin								
					update company_quarterly_calendar set cqc_quarter_no = @quarter_no where cqc_quarter_id = @temp_quarter_id
					set @quarter_no = @quarter_no + 1
					fetch next from temp_cursor2 into @temp_quarter_id
				end			
			close temp_cursor2	
			deallocate temp_cursor2

			fetch next from temp_cursor1 into @temp_yearId
			
		end	
	close temp_cursor1	
	deallocate temp_cursor1


end
